package com.ziyun.erp.modules.quoteProduct.service.impl;

import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.utility.New;
import com.ziyun.erp.modules.craftConfig.entity.GoodsCraftConfigEntity;
import com.ziyun.erp.modules.goods.dto.OptionDto;
import com.ziyun.erp.modules.goods.entity.GoodsEntity;
import com.ziyun.erp.modules.goods.service.GoodsService;
import com.ziyun.erp.modules.goods.service.impl.GoodsServiceImpl;
import com.ziyun.erp.modules.goodsCategory.entity.GoodsCategoryEntity;
import com.ziyun.erp.modules.goodsCategory.service.GoodsCategoryService;
import com.ziyun.erp.modules.order.vo.QuoteAllotCraftsVo;
import com.ziyun.erp.modules.productBaseInfo.entity.ProductBaseInfoEntity;
import com.ziyun.erp.modules.productBaseInfo.service.ProductBaseInfoService;
import com.ziyun.erp.modules.quoteAttribute.entity.QuoteAttributeEntity;
import com.ziyun.erp.modules.quoteAttribute.entity.QuoteAttributeOptionEntity;
import com.ziyun.erp.modules.quoteAttribute.entity.QuoteAttributeVO;
import com.ziyun.erp.modules.quoteAttribute.service.QuoteAttributeOptionService;
import com.ziyun.erp.modules.quoteAttribute.service.QuoteAttributeService;
import com.ziyun.erp.modules.quoteParts.entity.QuotePartsEntity;
import com.ziyun.erp.modules.quoteParts.service.QuotePartsService;
import com.ziyun.erp.modules.quoteProduct.dto.QuoteProductBaseInfoDto;
import com.ziyun.erp.modules.quoteProduct.vo.QuoteAttributeOptionVo;
import com.ziyun.erp.modules.quoteProduct.vo.QuoteProductBaseInfoVO;
import io.renren.common.exception.RRException;
import io.renren.common.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import com.ziyun.erp.modules.quoteProduct.dao.QuoteProductBaseInfoDao;
import com.ziyun.erp.modules.quoteProduct.entity.QuoteProductBaseInfoEntity;
import com.ziyun.erp.modules.quoteProduct.service.QuoteProductBaseInfoService;
import org.springframework.transaction.annotation.Transactional;


@Service("quoteProductBaseInfoService")
public class QuoteProductBaseInfoServiceImpl extends ServiceImpl<QuoteProductBaseInfoDao, QuoteProductBaseInfoEntity> implements QuoteProductBaseInfoService {

    @Autowired
    private GoodsCategoryService goodsCategoryService;

    @Autowired
    private QuoteAttributeService quoteAttributeService;

    @Autowired
    private QuoteAttributeOptionService quoteAttributeOptionService;

    @Autowired
    private QuotePartsService quotePartsService;

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private ProductBaseInfoService productBaseInfoService;


    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<QuoteProductBaseInfoEntity> page = this.selectPage(
                new Query<QuoteProductBaseInfoEntity>(params).getPage(),
                new EntityWrapper<QuoteProductBaseInfoEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils queryQuoteBaseInfoPage(Map<String, Object> params) {
        Page page = new Query<QuoteProductBaseInfoDto>(params).getPage();
        List<QuoteProductBaseInfoDto> list = this.baseMapper.selectQuoteBaseInfoList(page, params);
        page.setRecords(list);
        return new PageUtils(page);
    }

    /**
     * 获取 添加商品模板所需信息
     *
     * @return
     */
    @Override
    public Map<String, Object> getAddInfo() {
        Map<String, Object> rsMap = new HashMap<String, Object>();
        // 先获取商品分类
        List<GoodsCategoryEntity> categoryEntityList = goodsCategoryService.selectList(new EntityWrapper<GoodsCategoryEntity>()
                             .in("goods_type",new ArrayList<String>(Arrays.asList("print", "fast"))));
        List<Map> categoryTree = categoryTreeHandle(categoryEntityList, 0);
        rsMap.put("categoryTree", categoryTree);
        return rsMap;
    }

    /**
     * 根据分类获取属性选项
     *
     * @param categoryIds
     * @return
     */
    @Override
    public Map getAttributeOption(List<Integer> categoryIds) {
        Map rsMap = new HashMap();
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        // 将分类转换为 类别 用类别匹配查询
        // 注释: 此处理论只有一个 分类ID 只查询数码快印和商务印刷 皆为3级分类
        List<GoodsCategoryEntity> goodsCategoryList = this.goodsCategoryService.selectBatchIds(categoryIds);
        List<String> goodsTypes = new ArrayList<>();
        for (GoodsCategoryEntity goodsCategory : goodsCategoryList){
            goodsTypes.add(goodsCategory.getGoodsType());
        }
        // 加入通用类别
        goodsTypes.add("common");
        paramsMap.put("goodsTypes", goodsTypes);

        List<QuoteAttributeOptionVo> normalAttributeOptionVoList = this.baseMapper.selectNormalAttributeOption(paramsMap);
        List<QuoteAttributeOptionVo> materialAttributeOptionVoList = this.baseMapper.selectMaterialAttributeOption(paramsMap);
        rsMap.put("normalAttributeOptionList", normalAttributeOptionVoList);
        rsMap.put("materialAttributeOptionList", materialAttributeOptionVoList);
        return rsMap;
    }

    /**
     * 获取已经存在的商品分类
     * @param partsId
     * @param categoryId
     * @return
     */
    @Override
    public Map getExistAttributeOption(Integer partsId, Integer categoryId) {
        Map<String,Object> rsMap = new HashMap();
        // 通过部件 和分类查询出所有属性选项
       List<QuoteProductBaseInfoEntity> infoEntityList =  this.selectList(new EntityWrapper<QuoteProductBaseInfoEntity>()
                .eq(partsId!=null, "parts_id",partsId)
                .eq("category_id",categoryId));

       if (infoEntityList.size() == 0){
           throw new RRException("数据异常!");
       }
       //取出任意一个分类
        Integer category = infoEntityList.get(0).getCategoryId();
        // 将分类转换为 类别 用类别匹配查询
        GoodsCategoryEntity goodsCategory = this.goodsCategoryService.selectById(category);
        List<String> goodsTypes = new ArrayList<>();
        goodsTypes.add(goodsCategory.getGoodsType());
        // 加入通用类别
        goodsTypes.add("common");

        // 查询分类下的属性选项
        Map<String, Object> paramsMap = new HashMap<String, Object>();
        paramsMap.put("goodsTypes", goodsTypes);

        //处理普通属性
        List<QuoteAttributeOptionVo> normalAttributeOptionVoList = this.baseMapper.selectNormalAttributeOption(paramsMap);

        // 处理材料
        List<QuoteAttributeOptionVo> materialAttributeOptionVoList = this.baseMapper.selectMaterialAttributeOption(paramsMap);

        rsMap.put("normalAttributeOptionList", this.handleNormalAttributeOptionVoList(normalAttributeOptionVoList,infoEntityList,partsId,categoryId));
        rsMap.put("materialAttributeOptionData", this.handleMaterialAttributeOptionVoList(materialAttributeOptionVoList,partsId,categoryId));

        return rsMap;
    }

    /**
     * 处理普通属性 已选择选项
     * @param normalAttributeOptionVoList
     * @param infoEntityList
     * @param partsId
     * @param categoryId
     * @return
     */
    private List<QuoteAttributeOptionVo> handleNormalAttributeOptionVoList(List<QuoteAttributeOptionVo> normalAttributeOptionVoList, List<QuoteProductBaseInfoEntity> infoEntityList,Integer partsId, Integer categoryId){

        List<Map<String,Object>> attributeMapList =  this.selectMaps(new EntityWrapper<QuoteProductBaseInfoEntity>()
                .setSqlSelect("distinct(attribute_id) attributeId")
                .eq(partsId!=null,"parts_id",partsId)
                .eq("category_id",categoryId));
        // 遍历 将已经存在的属性选项 放入
        for (QuoteAttributeOptionVo quoteAttributeOptionVo : normalAttributeOptionVoList){
            // 先看属性是否存在
            if(this.isExistAttribute(quoteAttributeOptionVo.getId(),attributeMapList)){
                quoteAttributeOptionVo.setSelected(true);
            }
            List<Integer> normalSelectedOptionList = new ArrayList<Integer>();
            List<Map<String,Object>> normalSelectedTempOptionList = new ArrayList<Map<String,Object>>();
            List<Map<String,Object>> normalOptionList = quoteAttributeOptionVo.getNormalOptionList();
            for(Map map : normalOptionList){// 遍历普通属选项
                // 查看选项是否存在
                Integer optionId = Integer.parseInt(map.get("id").toString());
                QuoteProductBaseInfoEntity existBaseInfo = this.isExistOption(optionId,infoEntityList);
                if (existBaseInfo!= null ){
                    normalSelectedOptionList.add(optionId); // 组装选中列表
                    Map<String,Object> mapOption = new HashMap<String,Object>();
                    mapOption.put("id", optionId);//选项id
                    mapOption.put("optionName", map.get("optionName"));//选项
                    normalSelectedTempOptionList.add(mapOption); //组装选中选项teml

                    if(existBaseInfo.getIsDefault().intValue() ==1){// 默认optionId
                        quoteAttributeOptionVo.setNormalDefaultOption(optionId);
                    }
                }
            }
            quoteAttributeOptionVo.setNormalSelectedOptionList(normalSelectedOptionList);
            quoteAttributeOptionVo.setNormalSelectedTempOptionList(normalSelectedTempOptionList);
        }

        return  normalAttributeOptionVoList;
    }


    /**
     * 处理材料 已经选择属性选项
     * @param materialAttributeOptionVoList
     * @param partsId
     * @param categoryId
     * @return
     */
    private Map<String,Object> handleMaterialAttributeOptionVoList (List<QuoteAttributeOptionVo> materialAttributeOptionVoList,Integer partsId, Integer categoryId){
        //查询产品模板 选项相关信息
        Map<String ,Object> paramsMap = new HashMap<String ,Object>();
        paramsMap.put("partsId",partsId);
        paramsMap.put("categoryId",categoryId);
        List<Map<String,Object>> optionMapList = this.baseMapper.selectOptionBaseInfoList(paramsMap);

        Integer materialDefaultOptionName2 = null;
        String materialDefaultOptionKey = null;

        // 材料默认克重列表
        List<Map<String,Object>> materialDefaultOptionName2List = new ArrayList<Map<String,Object>>();
        // 遍历 将已经存在的属性选项 放入
        //材料默认选项列表
        List<Map<String,Object>> materialDefaultOptionList = new ArrayList<Map<String,Object>>();
        for (QuoteAttributeOptionVo quoteAttributeOptionVo : materialAttributeOptionVoList){
            // 先看optionKey是否存在
            if(this.isExistOption(quoteAttributeOptionVo.getOptionKey(),optionMapList)){
                // 组装相应的templete
                Map<String,Object> mapOption = new HashMap<String,Object>();
                mapOption.put("optionKey", quoteAttributeOptionVo.getOptionKey());//选项id
                mapOption.put("optionName", quoteAttributeOptionVo.getOptionName());//选项
                materialDefaultOptionList.add(mapOption); //组装选中选项teml

                quoteAttributeOptionVo.setSelected(true);

            }

            //查看选项是否存在 materialDefaultOption
            List<Integer> materialSelectedOptionList = new ArrayList<Integer>();

            // 取出选中的选项
            List<Map<String,Object>> materialOptionList = quoteAttributeOptionVo.getMaterialOptionList();
            for(Map map : materialOptionList){
                /*查看克重所在选项是否存在*/
                Integer optionId = Integer.parseInt(map.get("id").toString());
                Map existOptionMap = this.isExistOptionName2(optionId,optionMapList);
                if(existOptionMap!=null && existOptionMap.size()>0){ // optionKey 存在
                    materialSelectedOptionList.add(optionId); // 组装选中列表
                    if((Boolean) existOptionMap.get("isDefault")){ //默认值
                        materialDefaultOptionName2 = optionId;
                        materialDefaultOptionKey =  quoteAttributeOptionVo.getOptionKey();
                    }
                }
            }
            //再次循环找出 默认克重 模板列表
            for(Map map: materialOptionList){
                Integer optionId = Integer.parseInt(map.get("id").toString());
                Map existOptionMap = this.isExistOptionName2(optionId,optionMapList);
                if(existOptionMap!=null && existOptionMap.size()>0 && StringUtils.isNotEmpty(materialDefaultOptionKey) && existOptionMap.get("optionKey").equals(materialDefaultOptionKey)){
                    materialDefaultOptionName2List.add(map);
                }
            }
            quoteAttributeOptionVo.setMaterialSelectedOptionList(materialSelectedOptionList);

        }
        Map<String,Object> rsMap = new HashMap<String,Object>();
        rsMap.put("materialAttributeOptionList",materialAttributeOptionVoList);
        rsMap.put("materialDefaultOptionName2",materialDefaultOptionName2);
        rsMap.put("materialDefaultOptionName2List",materialDefaultOptionName2List);
        rsMap.put("materialDefaultOption",materialDefaultOptionKey);
        rsMap.put("materialDefaultOptionList",materialDefaultOptionList);


        return rsMap;
    }

    private Map<String,Object> isExistOptionName2(Integer optionId, List<Map<String, Object>> optionMapList) {
        Map<String, Object> mapReturn = new HashMap<String, Object>();
        for (Map map : optionMapList){
            Integer tempOptionId = Integer.parseInt(map.get("optionId").toString());
            if (tempOptionId.intValue() == optionId.intValue()){
                mapReturn = map;
                break;
            }
        }
        return  mapReturn;
    }

    /**
     * 材料选项
     * @param optionKey
     * @param optionMapList
     * @return
     */
    private boolean isExistOption(String optionKey, List<Map<String, Object>> optionMapList) {
        boolean flag = false;
        for(Map map : optionMapList){
            String tempOptionKey = map.get("optionKey").toString();
            if(tempOptionKey.equals(optionKey)){
                flag = true;
                break;
            }
        }
        return flag;
    }

    /**
     * 返回 该属性id是否在模板表选中
     * @param attributeId
     * @param baseInfo
     * @return
     */
    private boolean isExistAttribute(Integer attributeId, List<Map<String,Object>> baseInfo){
        boolean flag = false;
        for(Map map : baseInfo){
            Integer tempAttributeId = Integer.parseInt(map.get("attributeId").toString());
            if(tempAttributeId.intValue() == attributeId.intValue()){
                flag = true;
                break;
            }
        }
        return flag;
    }

    /**
     * 返回已经存在的模板 选项 并且判断是否默认值
     * @param optionId
     * @param quoteProductBaseInfoList
     * @return
     */
    private QuoteProductBaseInfoEntity isExistOption(Integer optionId, List<QuoteProductBaseInfoEntity> quoteProductBaseInfoList){
        QuoteProductBaseInfoEntity temp = null;
        for (QuoteProductBaseInfoEntity quoteProductBaseInfo : quoteProductBaseInfoList){
            if (quoteProductBaseInfo.getOptionId().intValue() == optionId.intValue()){

                temp = quoteProductBaseInfo;
                break;
            }
        }
        return  temp;
    }


    /**
     * 生成产品模板
     *
     * @param quoteProductBaseInfoVO
     */
    @Override
    @Transactional()
    public void generate(QuoteProductBaseInfoVO quoteProductBaseInfoVO) {
        //判断该部件或者分类是否存在
        if (quoteProductBaseInfoVO.getPartsId() !=null){
            //部件若存在 则必须唯一
            List<Map<String, Object>> partsList = this.selectMaps(new EntityWrapper<QuoteProductBaseInfoEntity>()
                    .setSqlSelect("id")
                    .eq("parts_id",quoteProductBaseInfoVO.getPartsId()));
            if(partsList!=null && partsList.size() > 0){
                throw new RRException("该部件已存在，请返回编辑!");
            }

        }else {
            // 部件不存在 则分类必须唯一
            List<Map<String, Object>> categoryList = this.selectMaps(new EntityWrapper<QuoteProductBaseInfoEntity>()
                    .setSqlSelect("id")
                    .eq("category_id",quoteProductBaseInfoVO.getCategoryId()));
            if(categoryList!=null && categoryList.size() > 0){
                throw new RRException("该分类已存在，请返回编辑!");
            }
        }


        // 插入数据库 生成产品模板
        this.insertBatch(this.handleWebDataToBaseInfoList(quoteProductBaseInfoVO));

    }

    /**
     * 更新产品模板
     * @param quoteProductBaseInfoVO
     */
    @Override
    @Transactional()
    public void updateProductTemplate(QuoteProductBaseInfoVO quoteProductBaseInfoVO) {
        //现将前台页面 解析成 模板数据
        List<QuoteProductBaseInfoEntity> quoteProductBaseInfoList =  this.handleWebDataToBaseInfoList(quoteProductBaseInfoVO);

        // 按照部件 分类查询出所有已经存在的模板
        List<QuoteProductBaseInfoEntity> infoEntityList =  this.selectList(new EntityWrapper<QuoteProductBaseInfoEntity>()
                .eq(quoteProductBaseInfoVO.getPartsId()!=null,"parts_id",quoteProductBaseInfoVO.getPartsId())
                .eq("category_id",quoteProductBaseInfoVO.getCategoryId()));

        //循环模板数据 进行比较判断
        for(QuoteProductBaseInfoEntity quoteProductBaseInfo: quoteProductBaseInfoList){
            QuoteProductBaseInfoEntity existBaseInfo =  this.isExistOption(quoteProductBaseInfo.getOptionId(),infoEntityList);
            if(existBaseInfo !=null){
                quoteProductBaseInfo.setId(existBaseInfo.getId());
                //创建人 创建日期不变
                quoteProductBaseInfo.setCreateUser(existBaseInfo.getCreateUser());
                quoteProductBaseInfo.setCreateDate(existBaseInfo.getCreateDate());

            }
        }

        // 按照 部件 选项 删除所有数据 再插入
        Map<String, Object> params = new HashMap<>();
        params.put("category_id", quoteProductBaseInfoVO.getCategoryId());
        if (quoteProductBaseInfoVO.getPartsId()!=null){
            params.put("parts_id",quoteProductBaseInfoVO.getPartsId());
        }
        this.baseMapper.deleteByMap(params);

        //再重新插入数据
        this.insertBatch(quoteProductBaseInfoList);

    }




    /**
     * 将页面数据转换为ProductBaseInfo List
     * @param quoteProductBaseInfoVO
     * @return
     */
    public List<QuoteProductBaseInfoEntity> handleWebDataToBaseInfoList(QuoteProductBaseInfoVO quoteProductBaseInfoVO){
        // 拆分数据组装成List <QuoteProductBaseInfoEntity>
        List<QuoteProductBaseInfoEntity> quoteProductBaseInfoEntityList = new ArrayList<>();
        //先处理 普通属性
        List<Map<String, Object>> normalAttributeOptionSelectedList = quoteProductBaseInfoVO.getNormalAttributeOptionSelectedList();
        if (normalAttributeOptionSelectedList != null && normalAttributeOptionSelectedList.size() > 0) {
            for (Map<String, Object> map : normalAttributeOptionSelectedList) {

                //选中的普通属性选项
                List<Integer> normalSelectedOptionList = (List<Integer>) map.get("normalSelectedOptionList");
                for (Integer optionId : normalSelectedOptionList) {//循环普通属性选项
                    //组装bean
                    QuoteProductBaseInfoEntity quoteProductBaseInfo = new QuoteProductBaseInfoEntity();
                    quoteProductBaseInfo.setPartsId(quoteProductBaseInfoVO.getPartsId()); //部件
                    quoteProductBaseInfo.setCategoryId(quoteProductBaseInfoVO.getCategoryId()); // 分类
                    quoteProductBaseInfo.setCreateDate(quoteProductBaseInfoVO.getCreateDate());
                    quoteProductBaseInfo.setCreateUser(quoteProductBaseInfoVO.getCreateUser());
                    quoteProductBaseInfo.setUpdateDate(quoteProductBaseInfoVO.getUpdateDate());
                    quoteProductBaseInfo.setUpdateUser(quoteProductBaseInfoVO.getUpdateUser());


                    Integer attributeId = Integer.parseInt(map.get("id").toString()); // 属性id
                    Integer normalDefaultOption = Integer.parseInt(map.get("normalDefaultOption").toString());// 默认选项
                    quoteProductBaseInfo.setAttributeId(attributeId);

                    quoteProductBaseInfo.setOptionId(optionId);
                    if (normalDefaultOption.intValue() == optionId.intValue()) {//默认选项
                        quoteProductBaseInfo.setIsDefault(1);
                    }
                    quoteProductBaseInfoEntityList.add(quoteProductBaseInfo);
                }

            }
        }
        //再处理材料属性
        List<Map<String, Object>> materialAttributeOptionSelectedList = quoteProductBaseInfoVO.getMaterialAttributeOptionSelectedList();
        if (materialAttributeOptionSelectedList != null && materialAttributeOptionSelectedList.size() > 0) {
            for (Map map : materialAttributeOptionSelectedList) {

                //选中的材料属性选项
                List<Integer> materialSelectedOptionList = (List<Integer>) map.get("materialSelectedOptionList");

                for (Integer optionId : materialSelectedOptionList) { //循环材料属性选项
                    //组装bean
                    QuoteProductBaseInfoEntity quoteProductBaseInfo = new QuoteProductBaseInfoEntity();
                    quoteProductBaseInfo.setPartsId(quoteProductBaseInfoVO.getPartsId()); //部件
                    quoteProductBaseInfo.setCategoryId(quoteProductBaseInfoVO.getCategoryId()); // 分类
                    quoteProductBaseInfo.setCreateDate(quoteProductBaseInfoVO.getCreateDate());
                    quoteProductBaseInfo.setCreateUser(quoteProductBaseInfoVO.getCreateUser());
                    quoteProductBaseInfo.setUpdateDate(quoteProductBaseInfoVO.getUpdateDate());
                    quoteProductBaseInfo.setUpdateUser(quoteProductBaseInfoVO.getUpdateUser());

                    Integer attributeId = Integer.parseInt(map.get("id").toString()); // 属性id
                    Integer materialDefaultOptionName2 = quoteProductBaseInfoVO.getMaterialDefaultOptionName2();// 默认选项
                    quoteProductBaseInfo.setAttributeId(attributeId);

                    quoteProductBaseInfo.setOptionId(optionId);
                    if (materialDefaultOptionName2.intValue() == optionId.intValue()) {//默认选项
                        quoteProductBaseInfo.setIsDefault(1);
                    }
                    quoteProductBaseInfoEntityList.add(quoteProductBaseInfo);
                }

            }
        }

        return  quoteProductBaseInfoEntityList;
    }

    @Override
    public List<QuoteAllotCraftsVo> getCraftsAllotInfo(Map<String, Object> queryMap) {
        return this.baseMapper.getCraftsAllotInfo(queryMap);
    }

    /**
     * 生成分类树
     *
     * @param categoryEntityList
     * @param pid
     * @return
     */
    private List<Map> categoryTreeHandle(List<GoodsCategoryEntity> categoryEntityList, int pid) {
        List<Map> resultList = new ArrayList<>();

        //获取顶级元素集合
        Integer parentId;
        for (GoodsCategoryEntity goodsCategory : categoryEntityList) {
            parentId = goodsCategory.getParentCategoryId();
            if (parentId == null || pid == parentId || pid == 0) {
                Map map = new HashMap();
                map.put("label", goodsCategory.getCategoryName());
                map.put("value", goodsCategory.getCategoryId());
                resultList.add(map);
            }
        }

        //获取每个顶层元素的子数据集合
        for (Map map : resultList) {
            int value = Integer.parseInt(map.get("value").toString());
            List<Map> temp = categoryTreeHandle(categoryEntityList, value);
            if (temp.size() > 0) {
                map.put("children", temp);
            }
        }
        return resultList;
    }

    /**
     * 根据分类获得所有模板表数据
     * @param categoryId
     */
    @Override
    public List<Map> getAllQuoteTemplate(Integer categoryId,Integer factoryId) {
        List<Map> existAttributeOptions = new ArrayList<>();
        //首先查询获得所有的部件id
        List<Integer> partsId = this.baseMapper.getPartsIdByCategoryId(categoryId);
        //查分类信息
        GoodsCategoryEntity categoryEntity = goodsCategoryService.selectById(categoryId);
        //遍历
        for (int i = 0;i < partsId.size();i++){
//            quotePartsService.selectById(partsId)
//            Map existAttributeOption = getExistAttributeOption(partsId.get(i), categoryId);
            Map<String, Object> existAttributeOption = new HashMap<>();
            //普通规格属性集合
            List<QuoteAttributeOptionVo> normalAttributeOptionVoList = new ArrayList<>();
            //材料规格属性集合
            Map<String,Object> rsMap = new HashMap<String,Object>();
            //材料规格属性集合
//             通过部件 和分类查询出所有属性选项
            List<QuoteProductBaseInfoEntity> infoEntityList =  this.selectList(new EntityWrapper<QuoteProductBaseInfoEntity>()
                    .eq(partsId.get(i)!=null, "parts_id",partsId.get(i))
                    .eq("category_id",categoryId));
            List<Integer> attributeIds = new ArrayList<>();
            //所有attribute的默认optionId
            List<Integer> defaultOptionIds = new ArrayList<>();
            for (int j = 0;j<infoEntityList.size();j++){
                if(attributeIds.indexOf(infoEntityList.get(j).getAttributeId()) == -1){
                    attributeIds.add(infoEntityList.get(j).getAttributeId());
                }
                if(infoEntityList.get(j).getIsDefault() == 1){
                    defaultOptionIds.add(infoEntityList.get(j).getOptionId());
                }
            }
            for(int k = 0;k<attributeIds.size();k++){
                //查出attribute对象
                QuoteAttributeEntity quoteAttributeEntity = quoteAttributeService.selectById(attributeIds.get(k));
                QuoteAttributeVO quoteAttributeVO = new QuoteAttributeVO();
                quoteAttributeVO.setQuoteAttributeEntity(quoteAttributeEntity);
                //根据partsId,attributeId查询出所有的option--->下列的option就是模板内所有的optionList
                List<QuoteAttributeOptionEntity> optionList = new ArrayList<>();
                if(partsId.get(i)!=null && partsId.get(i).intValue()!=0){
                    optionList = quoteAttributeOptionService.selectTemplateOptions(partsId.get(i),attributeIds.get(k));
                }else{
                    optionList = quoteAttributeOptionService.selectTemplateOptionsNew(categoryId,attributeIds.get(k));
                }
                List<Map<String,Object>> optionMapList = new ArrayList<>();
                Integer defaultOptionId = null;
                StringBuffer optionIds = new StringBuffer();
                for(int w = 0;w<optionList.size();w++){
                    Map<String,Object> optionMap = new HashMap();
                    if(defaultOptionIds.indexOf(optionList.get(w).getId()) != -1){
                        //给这些optionList设置了默认
                        defaultOptionId = optionList.get(w).getId();
                    }
                    optionIds.append(optionList.get(w).getId());
                    optionIds.append(",");
                    optionMap.put("id", optionList.get(w).getId());
                    optionMap.put("optionName", optionList.get(w).getOptionName());
                    optionMapList.add(optionMap);
                }
                //遍历optionList,将其转换为 QuoteAttributeOptionVo
                if(attributeIds.get(k) == 1){
                    //是材料选项
                    //根据optionIds,返回伪对象QuoteAttributeOptionVo
                    List<Map<String,Object>> optionKeyList = this.baseMapper.selectMaterialOptionKey(optionIds.toString());
                    List<QuoteAttributeOptionVo> materialAttributeOptionVoList = new ArrayList<>();
                    String materialDefaultOptionKey = null;
                    Integer materialDefaultOptionName2 = null;
                    if("print".equals(categoryEntity.getGoodsType())){
                        materialDefaultOptionName2 = defaultOptionId;
                    }
                    // 材料默认克重列表
                    List<Map<String,Object>> materialDefaultOptionName2List = new ArrayList<Map<String,Object>>();
                    //按optionKeyList遍历插入
                    for (int o = 0;o<optionKeyList.size();o++){
                        QuoteAttributeOptionVo quoteAttributeOptionVo = new QuoteAttributeOptionVo();
                        quoteAttributeOptionVo.setAttributeName(quoteAttributeEntity.getAttributeName());
                        quoteAttributeOptionVo.setId(attributeIds.get(k));
                        quoteAttributeOptionVo.setOptionKey((String) optionKeyList.get(o).get("optionKey"));
                        quoteAttributeOptionVo.setOptionName((String) optionKeyList.get(o).get("optionName"));
                        //设置所有模板表出现的该optionKey的选项--->根据optionIds和optionKey去查
                        List<Map<String,Object>> materialOptionList = this.baseMapper.selectOptionByOptionKeyAndOptionIds((String)optionKeyList.get(o).get("optionKey"),optionIds.toString());
                        quoteAttributeOptionVo.setMaterialOptionList(materialOptionList);
                        //设置有值的材料
//                        Integer factoryId = 1;
                        //遍历materialOptionList拿到属于该optionKey的optionIds
                        StringBuffer optionKeyOptionIds = new StringBuffer();
                        Boolean flag =false;
                        for(int p = 0;p<materialOptionList.size();p++){
                            optionKeyOptionIds.append(materialOptionList.get(p).get("id"));
                            optionKeyOptionIds.append(",");
                            //下面可能有类型转换的问题
                            if(Integer.parseInt(materialOptionList.get(p).get("id").toString()) == defaultOptionId){
                                flag= true;
                            }
                        }
                        List<Map<String,Object>> materialSelectedOption = this.baseMapper.selectHasPriceOption(factoryId, optionKeyOptionIds.toString());
                        //提取id作为集合
                        List<Integer> materialSelectedOptionList = new ArrayList<>();
//                        将下列代码注释,就是为了材料均不选择
                        //如果是商务印刷,添加默认
                        if("print".equals(categoryEntity.getGoodsType())){
                            for (int kk = 0;kk<materialSelectedOption.size();kk++){
                                Object id = materialSelectedOption.get(kk).get("id");
                                materialSelectedOptionList.add(Integer.parseInt(id.toString()));
                            }
                        }
                        quoteAttributeOptionVo.setMaterialSelectedOptionList(materialSelectedOptionList);
                        materialAttributeOptionVoList.add(quoteAttributeOptionVo);
                        //找出默认optionId所在的optionKey
                        if(flag){
                            //设置
                            materialDefaultOptionName2List = materialSelectedOption;
                            //设置默认选中的那个材料名--------------------------------->下列为测试
                            materialDefaultOptionKey = (String) optionKeyList.get(o).get("optionKey");
                        }
                    }
                    rsMap.put("materialAttributeOptionList",materialAttributeOptionVoList);
                    rsMap.put("materialDefaultOptionName2",materialDefaultOptionName2);
                    rsMap.put("materialDefaultOption",materialDefaultOptionKey);
                    rsMap.put("materialDefaultOptionName2List",materialDefaultOptionName2List);
                    rsMap.put("materialDefaultOptionList",optionKeyList);
                }else{
                    //是普通选项
                    QuoteAttributeOptionVo quoteAttributeOptionVo = new QuoteAttributeOptionVo();
                    if(quoteAttributeEntity != null){

                        handlerQuoteAttributeOptionVO(attributeIds, k, quoteAttributeEntity, optionMapList, defaultOptionId, quoteAttributeOptionVo,optionIds.toString(),null,partsId.get(i),factoryId);
                    }
                    normalAttributeOptionVoList.add(quoteAttributeOptionVo);
                }
                //查出默认的optionIds
                quoteAttributeVO.setOptionList(optionList);
            }
            if(partsId.size() > 1){
                //多部件
                QuotePartsEntity quotePartsEntity = quotePartsService.selectById(partsId.get(i));
                existAttributeOption.put("partsName",quotePartsEntity.getPartsName());
            }else{
                //单部件
                existAttributeOption.put("partsName",categoryEntity.getCategoryName());
            }
            existAttributeOption.put("normalAttributeOptionList",normalAttributeOptionVoList);
            existAttributeOption.put("materialAttributeOptionData",rsMap);
            existAttributeOption.put("partsId",partsId.get(i));
            existAttributeOption.put("categoryId",categoryId);
            existAttributeOptions.add(existAttributeOption);
        }
        return existAttributeOptions;
    }

    /**
     * 编辑商品时获得报价类规格信息
     * @param goodsId
     * @param factoryId
     * @return
     */
    @Override
    public List<Map> getQuoteAttributeInfo(Long goodsId,Integer factoryId) {
        GoodsEntity goodsEntity = goodsService.selectById(goodsId);
        Integer categoryId = goodsEntity.getCategoryId();

        List<Map> existAttributeOptions = new ArrayList<>();
        //首先查询获得所有的部件id
        List<Integer> partsId = this.baseMapper.getPartsIdByCategoryId(categoryId);
        //遍历
        for (int i = 0;i < partsId.size();i++){
            Map<String, Object> existAttributeOption = new HashMap<>();
            //普通规格属性集合
            List<QuoteAttributeOptionVo> normalAttributeOptionVoList = new ArrayList<>();
            //材料规格属性集合
            Map<String,Object> rsMap = new HashMap<String,Object>();
            //材料规格属性集合
//             通过部件 和分类查询出所有属性选项
            List<QuoteProductBaseInfoEntity> infoEntityList =  this.selectList(new EntityWrapper<QuoteProductBaseInfoEntity>()
                    .eq(partsId.get(i)!=null, "parts_id",partsId.get(i))
                    .eq("category_id",categoryId));
            List<Integer> attributeIds = new ArrayList<>();
            //所有attribute的默认optionId
            List<Integer> defaultOptionIds = new ArrayList<>();
            for (int j = 0;j<infoEntityList.size();j++){
                //将规格属性id全服放入集合
                if(attributeIds.indexOf(infoEntityList.get(j).getAttributeId()) == -1){
                    attributeIds.add(infoEntityList.get(j).getAttributeId());
                }
                //找到所有的默认选项放入集合
                if(infoEntityList.get(j).getIsDefault() == 1){
                    defaultOptionIds.add(infoEntityList.get(j).getOptionId());
                }
            }
            //查出所有材料类型的默认选项

            //遍历该部件下的所有规格
            for(int k = 0;k<attributeIds.size();k++){
                //查出attribute对象
                QuoteAttributeEntity quoteAttributeEntity = quoteAttributeService.selectById(attributeIds.get(k));
                QuoteAttributeVO quoteAttributeVO = new QuoteAttributeVO();
                quoteAttributeVO.setQuoteAttributeEntity(quoteAttributeEntity);
                //根据partsId,attributeId查询出所有的option--->下列的option就是模板内所有的optionList
                List<QuoteAttributeOptionEntity> optionList = new ArrayList<>();
                if(partsId.get(i)!=null && partsId.get(i).intValue()!=0){
                    optionList = quoteAttributeOptionService.selectTemplateOptions(partsId.get(i),attributeIds.get(k));
                }else{
                    optionList = quoteAttributeOptionService.selectTemplateOptionsNew(categoryId,attributeIds.get(k));
                }
                //optionMapList是这个规格下的所有选项id和选项名称的list集合-->用来做下拉选项的
                List<Map<String,Object>> optionMapList = new ArrayList<>();
                //每一个规格都有一个默认选项
                Integer defaultOptionId = null;
                //optionIds是这个规格下的所有选项id集
                StringBuffer optionIds = new StringBuffer();
                for(int w = 0;w<optionList.size();w++){
                    //optionMap就是所有选项的
                    Map<String,Object> optionMap = new HashMap();
                    if(defaultOptionIds.indexOf(optionList.get(w).getId()) != -1){
                        //给这些optionList设置了默认
                        defaultOptionId = optionList.get(w).getId();
                    }
                    optionIds.append(optionList.get(w).getId());
                    optionIds.append(",");
                    optionMap.put("id", optionList.get(w).getId());
                    optionMap.put("optionName", optionList.get(w).getOptionName());
                    optionMapList.add(optionMap);
                }
                //遍历optionList,将其转换为 QuoteAttributeOptionVo
                if(attributeIds.get(k) == 1){
                    //是材料选项
                    //根据optionIds,返回伪对象QuoteAttributeOptionVo
                    List<Map<String,Object>> optionKeyList = this.baseMapper.selectMaterialOptionKey(optionIds.toString());
                    List<QuoteAttributeOptionVo> materialAttributeOptionVoList = new ArrayList<>();
                    String materialDefaultOptionKey = null;
//                    Integer materialDefaultOptionName2 = defaultOptionId;
                    //上面的默认值要修改成实际选择的默认值--而不是模板的默认值
                    ProductBaseInfoEntity productBaseInfoEntity = null;
                    if(partsId.get(i)!=null && partsId.get(i).intValue()!=0){
                        optionList = quoteAttributeOptionService.selectTemplateOptions(partsId.get(i),attributeIds.get(k));
                        productBaseInfoEntity = productBaseInfoService.getEditSelectDefaultMaterialOptionTwo(goodsEntity.getGoodsId(),partsId.get(i));
                    }else{
                        productBaseInfoEntity = productBaseInfoService.getEditSelectDefaultMaterialOption(goodsEntity.getGoodsId());
                    }
                    if(productBaseInfoEntity == null){
                        throw new RRException("信息异常,该商品没有默认材料,商品spu:"+goodsId);
                    }
                    Integer materialDefaultOptionName2 = productBaseInfoEntity.getOptionId();
                    // 材料默认克重列表
                    List<Map<String,Object>> materialDefaultOptionName2List = new ArrayList<Map<String,Object>>();
                    //按optionKeyList遍历插入
                    for (int o = 0;o<optionKeyList.size();o++){
                        QuoteAttributeOptionVo quoteAttributeOptionVo = new QuoteAttributeOptionVo();
                        //设置规格名-->材料
                        quoteAttributeOptionVo.setAttributeName(quoteAttributeEntity.getAttributeName());
                        //设置规格id-->1
                        quoteAttributeOptionVo.setId(attributeIds.get(k));
                        //获得optionKey-->材料分类
                        quoteAttributeOptionVo.setOptionKey((String) optionKeyList.get(o).get("optionKey"));
                        //获得optionName-->材料值,其实就是克重
                        quoteAttributeOptionVo.setOptionName((String) optionKeyList.get(o).get("optionName"));
                        //设置所有模板表出现的该optionKey的选项--->根据optionIds和optionKey去查
                        List<Map<String,Object>> materialOptionList = this.baseMapper.selectOptionByOptionKeyAndOptionIds((String)optionKeyList.get(o).get("optionKey"),optionIds.toString());


                        quoteAttributeOptionVo.setMaterialOptionList(materialOptionList);
                        //设置有值的材料
//                        Integer factoryId = 1;
                        //遍历materialOptionList拿到属于该optionKey的optionIds
                        StringBuffer optionKeyOptionIds = new StringBuffer();
                        Boolean flag =false;
                        for(int p = 0;p<materialOptionList.size();p++){
                            optionKeyOptionIds.append(materialOptionList.get(p).get("id"));
                            optionKeyOptionIds.append(",");
                            //下面可能有类型转换的问题
                            if(Integer.parseInt(materialOptionList.get(p).get("id").toString()) == materialDefaultOptionName2){
                                flag= true;
                            }
                        }
                        //旧的发布时候的搜索
                        //List<Map<String,Object>> materialSelectedOption = this.baseMapper.selectHasPriceOption(factoryId, optionKeyOptionIds.toString());
                        //编辑界面查询是去product_base_info查询
                        //新的编辑时候的搜索
                        List<Map<String,Object>> materialSelectedOption = null;
                        if(partsId.get(i)!=null && partsId.get(i).intValue()!=0){
                            //含部件
                            materialSelectedOption = productBaseInfoService.selectEditHasPriceMaterialOption(goodsId,partsId.get(i),1,(String) optionKeyList.get(o).get("optionKey"));
                        }else{
                            materialSelectedOption = productBaseInfoService.selectEditHasPriceMaterialOptionTwo(goodsId,1,(String) optionKeyList.get(o).get("optionKey"));
                        }
                        //提取id作为集合
                        List<Integer> materialSelectedOptionList = new ArrayList<>();
                        for (int kk = 0;kk<materialSelectedOption.size();kk++){
                            Object id = materialSelectedOption.get(kk).get("id");
                            materialSelectedOptionList.add(Integer.parseInt(id.toString()));
                        }
                        quoteAttributeOptionVo.setMaterialSelectedOptionList(materialSelectedOptionList);
                        materialAttributeOptionVoList.add(quoteAttributeOptionVo);
                        //找出默认optionId所在的optionKey
                        if(flag){
                            //设置
                            materialDefaultOptionName2List = materialSelectedOption;
                            //设置默认选中的那个材料名--------------------------------->下列为测试
                            materialDefaultOptionKey = (String) optionKeyList.get(o).get("optionKey");
                        }
                    }
                    rsMap.put("materialAttributeOptionList",materialAttributeOptionVoList);
                    rsMap.put("materialDefaultOptionName2",materialDefaultOptionName2);
                    rsMap.put("materialDefaultOption",materialDefaultOptionKey);
                    rsMap.put("materialDefaultOptionName2List",materialDefaultOptionName2List);
                    rsMap.put("materialDefaultOptionList",optionKeyList);
                }else{
                    //是普通选项
                    QuoteAttributeOptionVo quoteAttributeOptionVo = new QuoteAttributeOptionVo();
                    //如果这个规格不为空,只是做非空校验
                    if(quoteAttributeEntity != null){
                        handlerQuoteAttributeOptionVO(attributeIds, k, quoteAttributeEntity, optionMapList, defaultOptionId, quoteAttributeOptionVo,optionIds.toString(),goodsId,partsId.get(i),factoryId);
                    }
                    normalAttributeOptionVoList.add(quoteAttributeOptionVo);
                }
                //查出默认的optionIds
                quoteAttributeVO.setOptionList(optionList);
            }
            if(partsId.size() > 1){
                //多部件
                QuotePartsEntity quotePartsEntity = quotePartsService.selectById(partsId.get(i));
                existAttributeOption.put("partsName",quotePartsEntity.getPartsName());
            }else{
                //单部件
                GoodsCategoryEntity categoryEntity = goodsCategoryService.selectById(categoryId);
                existAttributeOption.put("partsName",categoryEntity.getCategoryName());
            }
            existAttributeOption.put("normalAttributeOptionList",normalAttributeOptionVoList);
            existAttributeOption.put("materialAttributeOptionData",rsMap);
            existAttributeOption.put("partsId",partsId.get(i));
            existAttributeOption.put("categoryId",categoryId);
            existAttributeOptions.add(existAttributeOption);
        }
        return existAttributeOptions;
    }

    /**
     * 处理普通类的选项
     * @param attributeIds
     * @param k
     * @param quoteAttributeEntity
     * @param optionMapList
     * @param defaultOptionId
     * @param quoteAttributeOptionVo
     */
    private void handlerQuoteAttributeOptionVO(List<Integer> attributeIds, int k, QuoteAttributeEntity quoteAttributeEntity, List<Map<String, Object>> optionMapList,
               Integer defaultOptionId, QuoteAttributeOptionVo quoteAttributeOptionVo,String optionIds,Long goodsId,Integer partId,Integer sellerId) {
        //给这个包装类设置规格id:attributeId
        quoteAttributeOptionVo.setId(attributeIds.get(k));
        //设置规格名
        quoteAttributeOptionVo.setAttributeName(quoteAttributeEntity.getAttributeName());
        //设置模板下当前遍历规格的所有option选项-->
        quoteAttributeOptionVo.setNormalOptionList(optionMapList);
        quoteAttributeOptionVo.setAttributeTypeValue(quoteAttributeEntity.getAttributeTypeValue());
//        quoteAttributeOptionVo.setSe
        //设置用户配置了价格的默认选中的
        //根据工厂id和optionId返回这些配置了价格的optionMap
        //如果是工艺,则判断该价格是否存在
        //取attributeId的attributeType
        List<Integer> normalSelectedOptionList = new ArrayList<>();
        if(quoteAttributeEntity.getAttributeType().equals("craft")){
            if(goodsId == null){
                //发布场景
                //工艺类型的查询是否有工艺价格
//                Integer sellerId = 1;
                String optionOrigin = "quote_craft";
                List<OptionDto> craftPriceOptionList  = quoteAttributeOptionService.selectHasCraftPriceOption(sellerId,optionOrigin,optionIds);
                List<Map<String,Object>> normalSelectedTempOptionList = New.arrayList();
                for (OptionDto optionDto : craftPriceOptionList) {
                    Map<String, Object> map = New.hashMap();
                    map.put("id",optionDto.getId());
                    map.put("optionName",optionDto.getOptionName());
                    normalSelectedTempOptionList.add(map);
                }
                quoteAttributeOptionVo.setNormalSelectedTempOptionList(normalSelectedTempOptionList);
                //定义标记,判断默认选择的optionId是否出现在有价格里面
                Boolean flag = false;
                for (OptionDto craftPriceOption:craftPriceOptionList) {
                    Integer id = craftPriceOption.getId();
                    normalSelectedOptionList.add(id);
                    if(defaultOptionId.intValue() ==  id.intValue()){
                        flag = true;
                    }
                }
                //工艺类的判断默认选项是否别勾选了
                if(flag){
                    quoteAttributeOptionVo.setNormalDefaultOption(defaultOptionId);
                }else{
                    quoteAttributeOptionVo.setNormalDefaultOption(null);
                }
            }else{
                //编辑场景
                //发布场景
                //工艺类型的查询是否有工艺价格
//                Integer sellerId = 1;
//                String optionOrigin = "quote_craft";
//                List<Map<String, Object>> craftPriceOptionList  = quoteAttributeOptionService.selectHasCraftPriceOption(sellerId,optionOrigin,optionIds);
//                quoteAttributeOptionVo.setNormalSelectedTempOptionList(craftPriceOptionList);
                //该场景是编辑
                //先去查product_base_info的数据组合
                //                quoteAttributeOptionVo.setNormalSelectedTempOptionList(selectedMapList);
//                for(Map<String,Object> map2:selectedMapList) {
//                    Integer id = Integer.parseInt(map2.get("id").toString());
//                    normalSelectedOptionList.add(id);
//                }
                //定义标记,判断默认选择的optionId是否出现在有价格里面
                List<OptionDto> selectedMapList  = null;
                Integer defaultId = null;
                if(partId != null && partId.intValue() != 0){
                    selectedMapList  = productBaseInfoService.selectEditSelectOptionIds(goodsId,attributeIds.get(k),partId);
                    //获得默认的选项
                    defaultId = productBaseInfoService.getEditSelectDefaultOptionId(goodsId,attributeIds.get(k),partId);
                }else{
                    selectedMapList  = productBaseInfoService.selectEditSelectOptionIdsTwo(goodsId,attributeIds.get(k));
                    defaultId = productBaseInfoService.getEditSelectDefaultOptionIdTwo(goodsId,attributeIds.get(k));
                }
                List<Map<String,Object>> normalSelectedTempOptionList = New.arrayList();
                for (OptionDto optionDto : selectedMapList) {
                    Map<String, Object> map = New.hashMap();
                    map.put("id",optionDto.getId());
                    map.put("optionName",optionDto.getOptionName());
                    normalSelectedTempOptionList.add(map);
                }
                quoteAttributeOptionVo.setNormalSelectedTempOptionList(normalSelectedTempOptionList);
                Boolean flag = false;
                for (OptionDto craftPriceOption:selectedMapList) {
                    Integer id = craftPriceOption.getId();
                    normalSelectedOptionList.add(id);
                    if(defaultId.intValue() == id.intValue()){
                        flag = true;
                    }
                }
                //工艺类的判断默认选项是否别勾选了
                if(flag){
                    quoteAttributeOptionVo.setNormalDefaultOption(defaultId);
                }else{
                    quoteAttributeOptionVo.setNormalDefaultOption(null);
                }
            }
        }else{
            //optionMapList是所有的选项,但是现在要求修改,分两种情况,一种是发布时,一种是编辑时
            //场景一:编辑时-->查product_base_info的数据组合
            if(goodsId == null){
                //该场景是发布
                //普通类型的发布查询价格信息,编辑类型的查询商品信息
                quoteAttributeOptionVo.setNormalSelectedTempOptionList(optionMapList);
                for(Map<String,Object> map:optionMapList) {
                    Integer id = (Integer) map.get("id");
                    normalSelectedOptionList.add(id);
                }
                quoteAttributeOptionVo.setNormalDefaultOption(defaultOptionId);
            }else{
                //该场景是编辑
                //先去查product_base_info的数据组合
                List<OptionDto> selectedMapList  = null;
//                Integer defaultId = null;
                if(partId != null && partId.intValue() != 0){
                    selectedMapList  = productBaseInfoService.selectEditSelectOptionIds(goodsId,attributeIds.get(k),partId);
                    Integer defaultId = productBaseInfoService.getEditSelectDefaultOptionId(goodsId,attributeIds.get(k),partId);
                    quoteAttributeOptionVo.setNormalDefaultOption(defaultId);
                }else{
                    selectedMapList  = productBaseInfoService.selectEditSelectOptionIdsTwo(goodsId,attributeIds.get(k));
                    Integer defaultId = productBaseInfoService.getEditSelectDefaultOptionIdTwo(goodsId,attributeIds.get(k));
                    quoteAttributeOptionVo.setNormalDefaultOption(defaultId);
                }
                for(OptionDto map2:selectedMapList) {
                    Integer id = map2.getId();
                    normalSelectedOptionList.add(id);
                }
                List<Map<String,Object>> normalSelectedTempOptionList = New.arrayList();
                for (OptionDto optionDto : selectedMapList) {
                    Map<String, Object> map = New.hashMap();
                    map.put("id",optionDto.getId());
                    map.put("optionName",optionDto.getOptionName());
                    normalSelectedTempOptionList.add(map);
                }
                quoteAttributeOptionVo.setNormalSelectedTempOptionList(normalSelectedTempOptionList);
//                quoteAttributeOptionVo.setNormalDefaultOption(defaultId);
            }
        }
        quoteAttributeOptionVo.setNormalSelectedOptionList(normalSelectedOptionList);
//        Integer factoryId = 1;
//        List<Map<String,Object>> hasPriceOption = this.baseMapper.selectHasPriceOption(factoryId,optionIds);
//        quoteAttributeOptionVo.setNormalSelectedTempOptionList(hasPriceOption);
//        List<Integer> normalSelectedOptionList = new ArrayList<>();
//        for (Map<String,Object> map:hasPriceOption) {
//            Integer id = (Integer) map.get("id");
//            normalSelectedOptionList.add(id);
//        }
//        quoteAttributeOptionVo.setNormalSelectedOptionList(normalSelectedOptionList);

    }

}
